import { getAppTheme, onAppThemeChange } from '@/utils';
export default {
  data() {
    return {
      theme: 'light',
    };
  },
  methods: {
    getTheme() {
      this.theme = getAppTheme()?.theme == 'dark' ? 'dark' : 'light';
    },
    initTheme() {
      if (this.theme == 'dark') {
        setTimeout(() => {
          document.documentElement.setAttribute('theme-mode', 'black');
        }, 0);
      }
    },
    onThemeChange() {
      onAppThemeChange(res => {
        if (res.theme == 'dark') {
          document.documentElement.setAttribute('theme-mode', 'black');
          this.theme = 'dark';
        } else {
          document.documentElement.setAttribute('theme-mode', '');
          this.theme = 'light';
        }
      });
    },
  },
  mounted() {
    this.getTheme();
    this.initTheme();
    this.onThemeChange();
  },
};
